<?php
require_once 'config/config.php';
require_once 'includes/auth.php';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Session 测试</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; }
        .test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
        .success { background-color: #d4edda; border-color: #c3e6cb; }
        .error { background-color: #f8d7da; border-color: #f5c6cb; }
        .info { background-color: #d1ecf1; border-color: #bee5eb; }
        pre { background: #f8f9fa; padding: 10px; border-radius: 3px; overflow-x: auto; }
    </style>
</head>
<body>
    <h1>Admin Session 修复测试</h1>

    <div class="test-section info">
        <h3>测试说明</h3>
        <p>此页面用于测试session管理修复是否有效。请按以下步骤操作：</p>
        <ol>
            <li>访问 <a href="admin/login.php" target="_blank">Admin登录页面</a> 并登录</li>
            <li>返回此页面检查session状态</li>
            <li>重启PHP服务</li>
            <li>再次访问admin页面，验证是否仍能正常访问</li>
        </ol>
    </div>

    <div class="test-section">
        <h3>当前Session状态</h3>

        echo "<p><strong>Session ID:</strong> " . session_id() . "</p>";
        echo "<p><strong>Session状态:</strong> " . (session_status() === PHP_SESSION_ACTIVE ? 'Active' : 'Inactive') . "</p>";
        echo "<p><strong>Session保存路径:</strong> " . session_save_path() . "</p>";

        if (isLoggedIn()) {
            echo '<div class="success"><p>✅ 用户已登录</p>';
            $adminInfo = getAdminInfo();
            echo "<pre>" . json_encode($adminInfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre></div>";
        } else {
            echo '<div class="error"><p>❌ 用户未登录</p></div>';
        }
        ?>
    </div>

    <div class="test-section">
        <h3>Session配置信息</h3>
        <pre>
<?php
echo "Cookie Lifetime: " . ini_get('session.cookie_lifetime') . " seconds\n";
echo "GC Maxlifetime: " . ini_get('session.gc_maxlifetime') . " seconds\n";
echo "Use Strict Mode: " . (ini_get('session.use_strict_mode') ? 'Yes' : 'No') . "\n";
echo "Cookie HTTP Only: " . (ini_get('session.cookie_httponly') ? 'Yes' : 'No') . "\n";
echo "Session Name: " . session_name() . "\n";
?>
        </pre>
    </div>

    <div class="test-section">
        <h3>测试链接</h3>
        <ul>
            <li><a href="admin/login.php" target="_blank">Admin登录页面</a></li>
            <li><a href="admin/" target="_blank">Admin管理后台</a></li>
            <li><a href="admin/categories.php" target="_blank">分类管理</a></li>
            <li><a href="admin/navigations.php" target="_blank">导航管理</a></li>
        </ul>
    </div>

    <div class="test-section info">
        <h3>修复内容摘要</h3>
        <ul>
            <li>✅ 修复了doLogout()函数中的session_start()调用bug</li>
            <li>✅ 创建了统一的session管理系统</li>
            <li>✅ 增强了session完整性验证</li>
            <li>✅ 配置了安全的session参数</li>
            <li>✅ 移除了所有重复的session_start()调用</li>
        </ul>
    </div>
</body>
</html>